/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.comfacauca.xmlc2.dao;

import com.comfacauca.xmlc2.servicio.CombosI;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 *
 * @author eorozco
 */



public class CombosDAO implements CombosI{

    private static final String PERSISTENCE_UNIT_NAME = "comPU";
    private static EntityManagerFactory factory;
    
    @Override
    public List traerCombo(String tabla) {
        factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
        EntityManager em = factory.createEntityManager();        
        Query query = em.createQuery("SELECT r FROM "+tabla+" r");        
        List lista = query.getResultList();     
        return lista;
    }

    @Override
    public List traerCombo(int id, String tabla) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
    
    @Override
    public List traerCombo(String tabla, String pu) {
        factory = Persistence.createEntityManagerFactory(pu);
        EntityManager em = factory.createEntityManager();        
        Query query = em.createQuery("SELECT r FROM "+tabla+" r where locationsId=118");        
        List lista = query.getResultList();     
        return lista;
    }

    @Override
    public List traerCombo(String tabla, String pu, int userglpi) {
        factory = Persistence.createEntityManagerFactory(pu);
        EntityManager em = factory.createEntityManager();        
        Query query = em.createQuery("SELECT r FROM "+tabla+" r where usersIdRecipient = "+userglpi+" ");        
        List lista = query.getResultList();     
        return lista;
    }
    
    
}
